<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <title>e网批发管理后台</title>
  <?php include("common/conn.php"); if($_SESSION['userid']==""){echo "<script>window.location.href='login.php';</script>";} 

  if($_GET['del']=="ok"){
    $area = array(); 
    $area= $_POST['checkbox'];
    foreach ($area as $k=>$v){
      $srat1=mysql_query("DELETE FROM remen_shichang where id='".$v."'");
      $srat1=mysql_query("DELETE FROM remen_shichang_fenl_tu where remen_shichang_id='".$v."'");
    }

  }

// 排序
if ($_REQUEST[id] != '' && $_REQUEST[changeid] !='') {
  $id = $_REQUEST[id];
  $changeid = $_REQUEST[changeid];
  $query = mysql_query("UPDATE remen_shichang AS h1 JOIN remen_shichang AS h2 ON ( h1.id =".$id." AND h2.id = ".$changeid.") OR (h1.id = ".$changeid." AND h2.id=".$id.") SET h1.sort = h2.sort,h2.sort=h1.sort");
}
// 排序 end


  ?>
  <script type="text/javascript" src="js/jquery.min.js"></script>
  <link href="css/styles.css" rel="stylesheet" type="text/css" />
  <link href="css/style2.css" rel="stylesheet" type="text/css" />
  <link href="css/css.css" rel="stylesheet" type="text/css" />
  <style>
    .move_up,.move_down{
      margin-top: 0.5em;
      padding-top: 0.5em;
      display: inline-block;
      width: 4em !important;
      height: 2em !important;
      background-color: #FF963A !important;
      border-radius: 10px;
      margin: 0 0.5em 0.5em 0.5em;
    }
  </style>
</head>

<body>
  <!--header-->
  <?php include("common/header.php");?>
  <!--header end-->
  <div id="sub_nav">

    <div id="subnav_wrap" class="container_12">
      <div id="subnav" class=" grid_12">

      </div>

    </div>


  </div>
  <div class="container_12">
    <input type="button" class="submit" value="新增热门市场" onclick="add();">

  </div>
  <!-- end sub_nav -->
  <form action="?del=ok" method="post">
    <!-- EVERYTING BELOW IS THE MAIN CONTENT -->

    <div class="container_12">

      <table width="100%" border="0" cellpadding="0" cellspacing="0">

        <tr>

          <th width="5%" scope="col">
            <input type="checkbox" name="checkbox" id="checkbox" class="checkall" /><label for="checkbox"></label></th>
            <th width="18%" scope="col">图片</th>
            <th width="13%" scope="col">热门市场名称</th>
            <th width="18%" scope="col">操作</th>
          </tr>
    <?php 
    $perNumber=20; //每页显示的记录数
    if ($_GET[page]=="") {
      $page=1;
    } //如果没有值,则赋值1
    else

    {
    $page=$_GET['page']; //获得当前的页面值
    } //获得当前的页面值

    $count=mysql_query("select count(*) from remen_shichang ");

    //获得记录总数
    $rs=mysql_fetch_array($count); 
    $totalNumber=$rs[0];
    $totalPage=ceil($totalNumber/$perNumber); //计算出总页数

    $startCount=($page-1)*$perNumber; //分页开始,根据此方法计算出开始的

    $rert30=mysql_query("select * from remen_shichang  order by sort desc limit $startCount,$perNumber");

    while($sdg30=mysql_fetch_array($rert30)){

  ?>

  <tr>

    <td scope="col"><input type="checkbox" name="checkbox[]" id="checkbox"  value="<?php echo $sdg30[id];?>"/></td>
    <td scope="col"><img src="<?php echo $sdg30[images]; ?>" width="50%"  height="auto"></td>
    <td scope="col"><?php echo $sdg30[name];?></td>
    <td scope="col">
      <div class="youse2">
        <a href="#" class="move_up">上移</a>
        <a href="addremen_shichang.php?id=<?php echo $sdg30[id];?>">
          <span class="colorw">编辑</span>
        </a>
        <a href="#" class="move_down">下移</a>
        <a href="remen_shichang_img.php?id=<?php echo $sdg30[id];?>">
          <span class="colorw">分类活动图</span>
        </a>
      </div>

    </td>
  </tr>

  <?php }?>
</table>       
<div class="grid_12">

  <div class="clearfix"><input name="" type="submit" value="删除选中" class="submit"/></div>

  <!--foot-->
  <ul id="pagination">


    <?php  
    if ($page > 1) { //上一页 ?>
    <li><a     href="?page=1 ">首页</a></li>
    <li><a     href="?page=<?php echo ($page-1); ?> ">上一页</a></li>
    <?php }?>

    <?php if($page>=6){ ?>     

    <li><a     href="?page=<?php echo ($page-5); ?> "><?php echo ($page-5); ?></a></li>

    <?php } if($page>=5){ ?>     

    <li><a     href="?page=<?php echo ($page-4); ?> "><?php echo ($page-4); ?></a></li>

    <?php }if($page>=4){ ?>     

    <li><a     href="?page=<?php echo ($page-3); ?> "><?php echo ($page-3); ?></a></li>


    <?php }if($page>=3){ ?>     

    <li><a     href="?page=<?php echo ($page-2); ?> "><?php echo ($page-2); ?></a></li>

    <?php  }if($page>=2){ ?>     

    <li><a     href="?page=<?php echo ($page-1); ?> "><?php echo ($page-1); ?></a></li>

    <?php }?>


    <li class="active"><?php echo $page;?></li>


    <?php if( ($totalPage-1)>=$page){ ?>     

    <li><a     href="?page=<?php echo ($page+1); ?> "><?php echo ($page+1); ?></a></li>

    <?php } if( ($totalPage-2)>=$page){ ?>     

    <li><a     href="?page=<?php echo ($page+2); ?> "><?php echo ($page+2); ?></a></li>

    <?php } if( ($totalPage-3)>=$page){ ?>     

    <li><a     href="?page=<?php echo ($page+3); ?> "><?php echo ($page+3); ?></a></li>

    <?php } if( ($totalPage-4)>=$page){ ?>     

    <li><a     href="?page=<?php echo ($page+4); ?> "><?php echo ($page+4); ?></a></li>


    <?php
  }
  if ($_GET[page]<$totalPage and $_GET[page]!="") { //下一页 ?>
  <li><a     href="?page=<?php echo ($page+1); ?> ">下一页</a></li>
  <?php }

  if ($totalPage>1) { //下一页 ?>
  <li><a     href="?page=<?php echo $totalPage; ?> ">尾页</a></li>

  <?php }?>

  <li style="margin-left:100px;"><a href="javascript:;">总共有<?php echo $totalNumber;?>个</a></li>
  <div style="clear:both;"></div>

</ul>
<!--foot end-->

</div>           


</div>

<!-- end content wrap -->

</form>
</body>
<script type="text/javascript">
        $('.move_up').click(function(){
          var tr = $(this).parent().parent().parent();
          var id = tr.find('input[type="checkbox"]').val();
          var prev = tr.prev();
          var previd = prev.find('input[type="checkbox"]').val();
          var move_up = prev.find('.move_up');
          if (move_up.length >0) {
            tr.insertBefore(prev);
            var url = 'remen_shichang.php?id='+id+'&changeid='+previd;
            $.get(url,function(data){

            });
          }
        })

        $('.move_down').click(function(){
          var tr = $(this).parent().parent().parent();
          var id = tr.find('input[type="checkbox"]').val();
          var next = tr.next();
          var nextid = next.find('input[type="checkbox"]').val();
          var move_down = next.find('.move_down');
          if (move_down.length >0) {
            tr.insertAfter(next);
            var url = 'remen_shichang.php?id='+id+'&changeid='+nextid;
            $.get(url,function(data){

            });
          }
        })


        function add(){
          window.location.href="addremen_shichang.php";
        }
</script>
</html>
